package com.ywgt.system.auth;

import com.ywgt.utils.WriteJson;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 认证失败的统一处理类
 */
@Component
public class FailureAuthentication extends WriteJson implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        Map<String ,Object> info=new HashMap<>();
        e.printStackTrace();
        info.put("message",e.getMessage());
        this.write(httpServletRequest,httpServletResponse,info);
    }
}
